import { fromJS } from 'immutable';
import * as constants from './constants';

const defaultState = fromJS({
  dataSource: [],
  initialData: {},
  database: [],
  rrr: 'rrr',
  databaseConfig: {},
  basicInfo: {},
  metaTypeList: [],
  editShow: false,
});

const getCon = (state, action) => {
	return state.merge({
    'databaseConfig': action.databaseConfig,
    'basicInfo': action.basicInfo,
    'database': action.database,
	});
};

export default(state=defaultState, action) => {
  switch(action.type){
    case constants.TEST1:
      return state.set('dataSource',action.dataSource);
    case constants.TEST2:
      return state.set('database',action.database);
    case constants.TEST3:
      return getCon(state,action);
    case constants.SETFORMINITIALDATA:
      return state.set('initialData', action.data)
    case constants.SETMETATYPELIST:
      return state.set('metaTypeList', action.data)
    case constants.SETCATEEDITSHOW:
      return state.set('editShow', action.value)
    default: return state;
  }
}